﻿using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;

namespace NetCore.Filters
{
    /// <summary>
    /// Action的Filter
    /// </summary>
    public class CustomActionFilterAttribute : Attribute, IActionFilter
    {

        private ILogger<CustomActionFilterAttribute> _logger;
        public CustomActionFilterAttribute(ILogger<CustomActionFilterAttribute> logger)
        {
            _logger = logger;
        }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            context.HttpContext.Request.ContentType = "设置你的ContentType";
            _logger.LogDebug("ActionFilter Executing!");
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            _logger.LogDebug("ActionFilter Executed!");
        }
    }
}
